import { Injectable } from '@angular/core';
import { EntityConfig } from '../../core/entity-config.types';
import { ItemMasterDto } from '../../proxy/joy/erp/basic-archives/item-masters';
import { DatePipe } from '@angular/common';
import { LocalizationService } from '@abp/ng.core';

@Injectable({
  providedIn: 'root'
})
export class ItemMasterConfigService {
  private datePipe = new DatePipe('zh-CN');

  constructor(private localization: LocalizationService) {}

  getConfig(): EntityConfig {
    return {
      entityType: 'Joy.Erp.BasicArchives.ItemMasters.ItemMaster',
      propertys: [
        {
          name: 'Code',
          key: 'code',
          type: 'string',
          field: (item: ItemMasterDto) => item.code,
          width: 200,
          show: true,
          order: 0,
          fixed: 0
        },      
        {
          name: 'Name',
          key: 'name',
          type: 'string',
          field: (item: ItemMasterDto) => item.name,
          width: 200,
          show: true,
          order: 1,
          fixed: 0
        },
        {
          name: 'Spec',
          key: 'spec',
          type: 'string',
          field: (item: ItemMasterDto) => item.spec,
          width: 200,
          show: true,
          order: 2,
          fixed: 0
        },
        {
          name: 'Category.DisplayName',
          key: 'category.displayName',
          type: 'string',
          field: (item: ItemMasterDto) => item.category?.displayName || '',
          width: 150,
          show: true,
          order: 3,
          fixed: 0
        },
        {
          name: 'UnitGroup.Code',
          key: 'unitGroup.code',
          type: 'string',
          field: (item: ItemMasterDto) => item.unitGroup?.code || '',
          width: 150,
          show: false,
          order: 3,
          fixed: 0
        },
        {
          name: 'UnitGroup.GroupName',
          key: 'unitGroup.groupName',
          type: 'string',
          field: (item: ItemMasterDto) => item.unitGroup?.groupName || '',
          width: 150,
          show: true,
          order: 3,
          fixed: 0
        },
        {
          name: 'CanBePurchased',
          key: 'canBePurchased',
          type: 'boolean',
          field: (item: ItemMasterDto) => item.canBePurchased ? '是' : '否',
          width: 100,
          show: true,
          order: 4,
          fixed: 0
        },
        {
          name: 'Sellable',
          key: 'sellable',
          type: 'boolean',
          field: (item: ItemMasterDto) => item.sellable ? '是' : '否',
          width: 100,
          show: true,
          order: 5,
          fixed: 0
        },
        {
          name: 'CanBeProduced',
          key: 'canBeProduced',
          type: 'boolean',
          field: (item: ItemMasterDto) => item.canBeProduced ? '是' : '否',
          width: 100,
          show: true,
          order: 6,
          fixed: 0
        },
        {
          name: 'CanBeOutsourced',
          key: 'canBeOutsourced',
          type: 'boolean',
          field: (item: ItemMasterDto) => item.canBeOutsourced ? '是' : '否',
          width: 100,
          show: true,
          order: 7,
          fixed: 0
        },
        {
          name: 'Enabled',
          key: 'enabled',
          type: 'boolean',
          field: (item: ItemMasterDto) => item.enabled ? '启用' : '禁用',
          width: 100,
          show: true,
          order: 8,
          fixed: 0
        },
        {
          name: 'CreationTime',
          key: 'creationTime',
          type: 'date',
          field: (item: ItemMasterDto) => this.datePipe.transform(item.creationTime, 'yyyy-MM-dd'),
          width: 200,
          show: true,
          order: 9,
          fixed: 0
        },
      ]
    };
  }

  private l(key: string, ...params: string[]): string {
    return this.localization.instant(key, ...params);
  }
} 